package com.gbs.controller;


import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = {"/","user"})
public class UserController {

    @RequestMapping
    public String index(){
        System.out.println("主页");
        return "common/index";
    }

    @RequestMapping(value = "/loginPage" )
    public String loginPage(@RequestParam(value = "error", required = false) String error, Model model){
        System.out.println("登录页");
        if (error != null) {
        	model.addAttribute("error", "用户名或密码错误"); 
            return "loginFailure";
        }        
        return "common/login";
    }
    @RequestMapping(value = "/user/login",method=RequestMethod.POST)
    @ResponseBody
    public Map login(@RequestParam(value="username",required=true) String username,
    	    @RequestParam(value="password",required=true) String password){
        System.out.println("正在登陆---------");
        
       
        System.out.println("-------"+username+"---"+password);
        if(username.equals("worlk")&&password.equals("123456")) {
            //return "index";
        	System.out.println("登陆成功");
        }
        return new HashMap<>();
    }
    @RequestMapping(value = "/user/guest")
    public String loginAsGuest(HttpServletRequest request){
        System.out.println("普通用户");       
        return "guest";
    }
       
}
